package com.yxp.core.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBConnUtil {

	static String url = "jdbc:oracle:thin:@192.168.241.132:1521:XE"; 
	static String username = "yxptest"; 
	static String password = "root"; 
    static Connection  conn = null;
	static ResultSet rs = null;
	static PreparedStatement ps =null;
	
	public static void init(){
		   try {
		     Class.forName("oracle.jdbc.OracleDriver");
		     conn = DriverManager.getConnection(url,username,password);
		   } catch (Exception e) {
		     System.out.println("init [SQL驱动程序初始化失败！]");
		     e.printStackTrace();
		   }
		 }
		 public static int addUpdDel(String sql){
		   int i = 0;
		   try {
		     PreparedStatement ps =  conn.prepareStatement(sql);
		     i =  ps.executeUpdate();
		   } catch (SQLException e) {
		     System.out.println("sql数据库增删改异常");
		     e.printStackTrace();
		   }
		   
		   return i;
		 }
		 public static ResultSet selectSql(String sql){
		   try {
		     ps =  conn.prepareStatement(sql);
		     rs =  ps.executeQuery(sql);
		   } catch (SQLException e) {
		     System.out.println("sql数据库查询异常");
		     e.printStackTrace();
		   }
		   return rs;
		 }
		 public static void closeConn(){
		   try {
		     conn.close();
		   } catch (SQLException e) {
		     System.out.println("sql数据库关闭异常");
		     e.printStackTrace();
		   }
		 }
	
}
